home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 July / macformat52.iso / mac / Shareware Plus / Developers / YAAF v1.0 alpha 1 / Headers / Core / XApplication.h next >
Encoding:
C/C++ Source or Header  |  1997-04-24  |  9.6 KB  |  407 lines

  1. /*    XGApplication.h
  2.  *
  3.  *        This is the application class object; this is the thing which
  4.  *    handles setting up the main event loop.
  5.  */
  6.  
  7. /*  YAAF - Yet another application framework
  8.  *  Copyright (C) 1997 William Edward Woody and In Phase Consulting
  9.  *  
  10.  *  This library is free software; you can redistribute it
  11.  *  and/or modify it under the terms of the GNU Library
  12.  *  General Public License as published by the Free Software
  13.  *  Foundation; either version 2 of the License, or any
  14.  *  later version.
  15.  *  
  16.  *  This library is distributed in the hope that it will be
  17.  *  useful, but WITHOUT ANY WARRANTY; without even the implied
  18.  *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
  19.  *  PURPOSE. See the GNU Library General Public License for
  20.  *  more details.
  21.  *  
  22.  *  You should have received a copy of the GNU Library General
  23.  *  Public License along with this library; if not, write to the
  24.  *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25.  *  Boston, MA 02111-1307, USA.
  26.  *  
  27.  *  To contact the author, either e-mail me at
  28.  *  woody@alumni.caltech.edu, or write to us at
  29.  *  
  30.  *          William Edward Woody
  31.  *          In Phase Consulting
  32.  *          1545 Ard Eevin Avenue
  33.  *          Glendale, CA 91202
  34.  */
  35.  
  36. #ifndef __XAPPLICATION_H__
  37. #define __XAPPLICATION_H__
  38.  
  39. #include <XConfig.h>
  40. #include <XEvent.h>
  41.  
  42. #if defined(__MWERKS__)
  43.     #if defined(macintosh)
  44.         #pragma options align=power
  45.     #endif
  46.     #if defined(__INTEL__)
  47.         #pragma pack(push,2)
  48.     #endif
  49. #endif
  50.  
  51. /************************************************************************/
  52. /*                                                                        */
  53. /*    Forwards                                                            */
  54. /*                                                                        */
  55. /************************************************************************/
  56.  
  57. class XGView;
  58. class XGWindow;
  59. class XGMenuBar;
  60.  
  61. /************************************************************************/
  62. /*                                                                        */
  63. /*    Class Declarations                                                    */
  64. /*                                                                        */
  65. /************************************************************************/
  66.  
  67. /*    XGAppCore
  68.  *
  69.  *        This is the low level application core. This contains the
  70.  *    code for handling the generic event loop.
  71.  *
  72.  *        This is an abstract class--we generate the events here, but
  73.  *    we don't know where we send those events. That's left for the
  74.  *    children, who maintain and manage the various configurations.
  75.  */
  76.  
  77. class XGAppCore : public XGDispatch, public XGFocus {
  78.     public:
  79.         /*
  80.          *    Construction/Destruction
  81.          */
  82.         
  83.                                 XGAppCore();
  84.         virtual                    ~XGAppCore();
  85.         
  86.         /*
  87.          *    Event callbacks
  88.          */
  89.         
  90. #if OPT_MACOS == 1
  91.         virtual long            Open(FSSpec *);
  92.         virtual long            Print(FSSpec *);
  93.         virtual long            New(void);
  94.         virtual long            Quit(void);
  95.         
  96.         virtual bool            FilterEvent(EventRecord *);
  97.         
  98.         void                    _DoActive(WindowPtr w, short flag);
  99. #endif
  100.  
  101. #if OPT_WINOS == 1
  102.         virtual void            CommandLine(short argc, char **argv);
  103.         virtual long            Quit(void);
  104.         
  105.         virtual bool            FilterEvent(MSG *);
  106. #endif
  107.  
  108.         /*
  109.          *    Event loop processing
  110.          */
  111.         
  112.         virtual void            Run(void);        // Run event loop
  113.         virtual bool            _RunOnce(XGWindow *);
  114.         virtual void            Exit(void);        // Do the 'quit' command
  115.  
  116.         /*
  117.          *    Root event processing
  118.          */
  119.         
  120.         virtual void            ShowCopyright(void);
  121.         long                    ReceiveDispatch(long,long,void *);
  122.         
  123.         /*
  124.          *    Current focus support
  125.          */
  126.         
  127.         virtual XGMenuBar        *_GetCurMenu() = 0;
  128.         virtual XGFocus            *_GetCurFocus() = 0;
  129.  
  130.         /*
  131.          *    Modal support
  132.          */
  133.         
  134.         bool                    IsModalWindow()
  135.                                     {
  136.                                         return (_fModalWindow) ? true : false;
  137.                                     }
  138.     private:
  139.         bool                    fQuitFlag;            // Quit?
  140.         XGWindow                *_fModalWindow;        // Modal window?
  141.  
  142. #if OPT_MACOS == 1
  143.         /*
  144.          *    Internal Support
  145.          */
  146.         
  147.         void                    InvalidateCornerIcon(WindowPtr);
  148.         void                    DrawCornerIcon(WindowPtr);
  149.         
  150.         /*
  151.          *    Drag/drop support
  152.          */
  153.         
  154.         static void                InitOS6Finder(void);
  155.         static OSErr            GotRequiredParams(AppleEvent *);
  156.         static pascal OSErr        AEHandleProc(AppleEvent *, AppleEvent *, long);
  157.         
  158.         /*
  159.          *    Event loop dispatch
  160.          */
  161.  
  162.         void                    DoEvent(EventRecord *);
  163.         
  164.         /*
  165.          *    Mouse event processing
  166.          */
  167.         
  168.         void                    DoMouse(EventRecord *);
  169.         void                    DoMouseDown(WindowPtr, Point, short);
  170.         void                    DoMouseMove(EventRecord *);
  171.  
  172.         void                    DoUpdate(EventRecord *);
  173.         void                    DoKeyDown(EventRecord *);
  174.         void                    DoOSEvent(EventRecord *);
  175.         
  176.         void                    DoMenu(long);
  177.         
  178.         bool                    DoClose(WindowPtr);
  179.         
  180.         /*
  181.          *    Internal stuff
  182.          */
  183.         
  184.         bool                    fFront;
  185.         
  186.         Point                    fLastClickPos;
  187.         long                    fLastClickTime;
  188. #endif
  189.  
  190. #if OPT_WINOS == 1
  191.         void                    UpdateFocus();
  192.         void                    CallCommandLine();
  193. #endif
  194. };
  195.  
  196. /************************************************************************/
  197. /*                                                                        */
  198. /*    Single Window Application Type                                        */
  199. /*                                                                        */
  200. /************************************************************************/
  201.  
  202. /*    XGAppSingleWindow
  203.  *
  204.  *        This implements a single-window application. On Windows, this
  205.  *    creates an SDI window application; on the Macintosh this creates
  206.  *    an application which quits as soon as the window is closed.
  207.  *
  208.  *        The way this works is to create a single menu bar object
  209.  *    (in Windows, in the opened window), and update the menu bar
  210.  *    according to the messages received by 'ReceiveDispatch' (on the
  211.  *    periodic events).
  212.  *
  213.  *        When the main window close event is received, we terminate
  214.  *    the event loop and quit this program.
  215.  */
  216.  
  217. class XGAppSingleWindow : public XGAppCore, public XGBroadcast {
  218.     public:
  219.                                 XGAppSingleWindow();
  220.         virtual                    ~XGAppSingleWindow();
  221.         
  222.         /*
  223.          *    Application initialization procedures
  224.          */
  225.         
  226.         void                    Run(void);
  227.         void                    ReceiveBroadcast(long,long,void *);
  228.         long                    ReceiveDispatch(long,long,void *);
  229.  
  230.         /*
  231.          *    Overrides--this determines how we handle the focus
  232.          */
  233.          
  234.         virtual XGMenuBar        *_GetCurMenu();
  235.         virtual XGFocus            *_GetCurFocus();
  236.  
  237.     private:
  238.         XGWindow                *fMyWindow;
  239.         XGMenuBar                *fMyMenuBar;
  240.         
  241.         /*
  242.          *    Initialization
  243.          */
  244.  
  245. #if OPT_WINOS == 1
  246.         void                    _InitInstance();
  247.         void                    _InitApplication();
  248. #endif
  249. };
  250.  
  251. /************************************************************************/
  252. /*                                                                        */
  253. /*    Multiple Window Application Type                                    */
  254. /*                                                                        */
  255. /************************************************************************/
  256.  
  257. /*    WListRecord
  258.  *
  259.  *        This is an internal record used to record the list of windows that
  260.  *    are in my application
  261.  */
  262.  
  263. struct _WLstRecord {
  264.     short                        menuAccel;
  265.     short                        menuID;
  266.     XGMenuBar                    *fMenuBar;
  267.     XGWindow                    *fWindow;
  268. };
  269.  
  270. /*    XGAppMultiWindow
  271.  *
  272.  *        This implements a multi-window application. On Windows, this
  273.  *    creates an MDI window application; on the Macintosh this creates
  274.  *    the standard multi-window application
  275.  *
  276.  *        This works by creating a global menu bar, and maintaining both
  277.  *    that menu bar and a global table of all the open windows. (This
  278.  *    is used to maintain the window menu.)
  279.  *
  280.  *        We terminate only when we receive the standard quit command.
  281.  */
  282.  
  283. class XGAppMultiWindow : public XGAppCore, public XGBroadcast {
  284.     public:
  285.                                 XGAppMultiWindow(char *appName = NULL);
  286.         virtual                    ~XGAppMultiWindow();
  287.         
  288.         /*
  289.          *    Application initialization procedures
  290.          */
  291.         
  292.         void                    ReceiveBroadcast(long,long,void *);
  293.         long                    ReceiveDispatch(long,long,void *);
  294.  
  295.         /*
  296.          *    Overrides--this determines how we handle the focus
  297.          */
  298.          
  299.         virtual XGMenuBar        *_GetCurMenu();
  300.         virtual XGFocus            *_GetCurFocus();
  301.  
  302.     private:
  303.         /*
  304.          *    Initialization
  305.          */
  306.  
  307. #if OPT_WINOS == 1
  308.         void                    _InitInstance(char *);
  309.         void                    _InitApplication();
  310. #endif
  311.  
  312.         /*
  313.          *    Support routines
  314.          */
  315.         
  316.         void                    _CreateWindow(XGWindow *);
  317.         void                    _DestroyWindow(XGWindow *);
  318.         void                    _RenameWindow(XGWindow *);
  319.         
  320.         void                    _SortWindowList();
  321.         void                    _UpdateWindowMenu();
  322.         
  323.         void                    _TileWindows();
  324.         void                    _CascadeWindows();
  325.  
  326. #if OPT_WINOS
  327.         void                    _ArrangeIcons();
  328. #endif
  329.  
  330.         /*
  331.          *    Internal structures
  332.          */
  333.         
  334.         XGDynArray<_WLstRecord>    fWindowList;
  335.         XGMenuBar                *fMyMenuBar;
  336. };
  337.  
  338.  
  339. /************************************************************************/
  340. /*                                                                        */
  341. /*    Startup Procedure                                                    */
  342. /*                                                                        */
  343. /************************************************************************/
  344.  
  345. /*    StartApplication
  346.  *
  347.  *        This is the very first thing that gets called when an application
  348.  *    is started up. This expects you to return an XGAppCore descendant
  349.  *    and do initialization specific to the particular application type.
  350.  */
  351.  
  352. extern XGAppCore *StartApplication(void);
  353.  
  354. /************************************************************************/
  355. /*                                                                        */
  356. /*    Application Globals                                                    */
  357. /*                                                                        */
  358. /************************************************************************/
  359.  
  360. extern XGAppCore                *_GApp;
  361.  
  362. /************************************************************************/
  363. /*                                                                        */
  364. /*    Windows specific madness                                            */
  365. /*                                                                        */
  366. /************************************************************************/
  367.  
  368. #if OPT_WINOS == 1
  369.  
  370. extern char                        _GMainClass[];
  371. extern char                        _GWindowClass[];
  372. extern char                        _GViewClass[];
  373. extern char                        _GDlogClass[];
  374.  
  375. extern LRESULT CALLBACK            _GMainMDIWindowProc(HWND,UINT,WPARAM,LPARAM);
  376. extern LRESULT CALLBACK            _GChildWindowProc(HWND,UINT,WPARAM,LPARAM);
  377. extern LRESULT CALLBACK            _GSingleWindowProc(HWND,UINT,WPARAM,LPARAM);
  378. extern LRESULT CALLBACK            _GViewWindowProc(HWND,UINT,WPARAM,LPARAM);
  379.  
  380. extern HWND                        _GMainWindow;        /* main window here    */
  381. extern HWND                        _GMDIWindow;        /* non-NULL == MDI    */
  382.  
  383. extern XGWindow                    *_GWindow;
  384. extern XGView                    *_GView;
  385.  
  386.  
  387. #endif
  388.  
  389. #if OPT_MACOS == 1
  390.  
  391. extern EventRecord                _GCurEvent;
  392.  
  393. #endif
  394.  
  395.  
  396. #if defined(__MWERKS__)
  397.     #if defined(macintosh)
  398.         #pragma options align=reset
  399.     #endif
  400.     #if defined(__INTEL__)
  401.         #pragma pack(pop)
  402.     #endif
  403. #endif
  404.  
  405.  
  406. #endif /* __XAPPLICATION_H__ */
  407.